package com.ruoyi.smtdashboard.mapper;

import com.ruoyi.smtdashboard.domain.entity.Smtdashboard;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface SmtTableMapper {


    @Results(id = "qualityResultMap", value = {
            @Result(property = "id", column = "id"),
            @Result(property = "year", column = "year"),
            @Result(property = "month", column = "month"),
            @Result(property = "line", column = "line"),

            // Claim 相关字段
            @Result(property = "claimTotal", column = "claim_total"),
            @Result(property = "claimH1", column = "claim_h1"),
            @Result(property = "claimC", column = "claim_c"),

            // Sorting Fee 字段
            @Result(property = "sortingFeeTotal", column = "sorting_fee_total"),
            @Result(property = "sortingFeeIqc", column = "sorting_fee_iqc"),
            @Result(property = "sortingFeeClaim", column = "sorting_fee_claim"),

            // 生产指标
            @Result(property = "inputAmount", column = "input_amount"),
            @Result(property = "scarpAmount", column = "scarp_amount"),
            @Result(property = "scarpRate", column = "scarp_rate"),
            @Result(property = "nonConformity", column = "non_conformity"),
            @Result(property = "capa", column = "capa"),

            // OQC 检验数据
            @Result(property = "oqcScanQty", column = "oqc_scan_qty"),
            @Result(property = "oqcScanNgQty", column = "oqc_scan_ng_qty"),
            @Result(property = "oqcScanNg", column = "oqc_scan_ng"),
            @Result(property = "oqcInspLot", column = "oqc_insp_lot"),
            @Result(property = "oqcRejectLot", column = "oqc_reject_lot"),
            @Result(property = "oqcLrr", column = "oqc_lrr"),
            @Result(property = "oqcInspQty", column = "oqc_insp_qty"),
            @Result(property = "oqcNgQty", column = "oqc_ng_qty"),
            @Result(property = "oqcDppm", column = "oqc_dppm"),

            // OBA 检验数据
            @Result(property = "obaTimes", column = "oba_times"),
            @Result(property = "obaRejectTime", column = "oba_reject_time"),
            @Result(property = "obaNg", column = "oba_ng"),

            // IPQC 检验数据
            @Result(property = "ipqcFindings", column = "ipqc_findings"),
            @Result(property = "ipqcMajor", column = "ipqc_major"),
            @Result(property = "ipqcMinor", column = "ipqc_minor"),
            @Result(property = "ipqcCloseMil", column = "ipqc_close_mil"),
            @Result(property = "ipqcCloseRate", column = "ipqc_close_rate"),

            // 第三方检验数据
            @Result(property = "partyFindings3Rd", column = "party_findings_3rd"),
            @Result(property = "partyMajor3Rd", column = "party_major_3rd"),
            @Result(property = "partyMinor3Rd", column = "party_minor_3rd"),
            @Result(property = "partyCloseMil3Rd", column = "party_close_mil_3rd"),
            @Result(property = "partyCloseRate3Rd", column = "party_close_rate_3rd"),

            // 合规性检查
            @Result(property = "complianceTotal", column = "compliance_total"),
            @Result(property = "compCustomer", column = "comp_customer"),
            @Result(property = "compInternal", column = "comp_internal"),

            // FOX 指标
            @Result(property = "foxTotal", column = "fox_total"),
            @Result(property = "foxIct", column = "fox_ict"),
            @Result(property = "foxSpi", column = "fox_spi"),
            @Result(property = "foxFpy", column = "fox_fpy"),
            @Result(property = "foxDelay", column = "fox_delay"),

            // SPI 测试
            @Result(property = "spiInput", column = "spi_input"),
            @Result(property = "spiOutput", column = "spi_output"),
            @Result(property = "spiFpy", column = "spi_fpy"),

            // AOI 测试
            @Result(property = "aoiInput", column = "aoi_input"),
            @Result(property = "aoiFpQty", column = "aoi_fp_qty"),
            @Result(property = "aoiOutput", column = "aoi_output"),
            @Result(property = "aoiFpy", column = "aoi_fpy"),
            @Result(property = "aoiFy", column = "aoi_fy"),

            // ICT 测试
            @Result(property = "ictInput", column = "ict_input"),
            @Result(property = "ictFpQty", column = "ict_fp_qty"),
            @Result(property = "ictOutput", column = "ict_output"),
            @Result(property = "ictFpy", column = "ict_fpy"),
            @Result(property = "ictFy", column = "ict_fy"),

            //追加数据IPQC+第三方
            @Result(property = "ipqcLatestCloseMil", column = "ipqc_latest_close_mil"),
            @Result(property = "partyLatestCloseMil", column = "party_latest_close_mil")
    })
    @Select("<script>" +
            "select * from smtdashboard"+
            "  where 1=1"+
            "  and year=#{year}"+
            "<if test='month.size()>0 and month !=null '>  and month in" +
            "    <foreach item='item' collection='month' open='(' separator=',' close=')'>" +
            "        #{item}" +
            "    </foreach>" +
            "</if>"+
            "<if test='line.size()>0 and line !=null '>  and line in" +
            "    <foreach item='item' collection='line' open='(' separator=',' close=')'>" +
            "        #{item}" +
            "    </foreach>" +
            "</if>"+
            "</script>")
    List<Smtdashboard> qreuySmtTable(@Param("year")String year,@Param("month")List<String> month,@Param("line")List<String> list);


    @Insert("<script>" +
            "INSERT INTO smtdashboard (\n" +
            "            id, \n" +
            "            year, \n" +
            "            month, \n" +
            "            line, \n" +
            "            claim_total, \n" +
            "            claim_h1, \n" +
            "            claim_c, \n" +
            "            sorting_fee_total, \n" +
            "            sorting_fee_iqc, \n" +
            "            sorting_fee_claim, \n" +
            "            input_amount, \n" +
            "            scarp_amount, \n" +
            "            scarp_rate, \n" +
            "            non_conformity, \n" +
            "            capa, \n" +
            "            oqc_scan_qty, \n" +
            "            oqc_scan_ng_qty, \n" +
            "            oqc_scan_ng, \n" +
            "            oqc_insp_lot, \n" +
            "            oqc_reject_lot, \n" +
            "            oqc_lrr, \n" +
            "            oqc_insp_qty, \n" +
            "            oqc_ng_qty, \n" +
            "            oqc_dppm, \n" +
            "            oba_times, \n" +
            "            oba_reject_time, \n" +
            "            oba_ng, \n" +
            "            ipqc_findings, \n" +
            "            ipqc_major, \n" +
            "            ipqc_minor, \n" +
            "            ipqc_close_mil, \n" +
            "            ipqc_close_rate, \n" +
            "            party_findings_3rd, \n" +
            "            party_major_3rd, \n" +
            "            party_minor_3rd, \n" +
            "            party_close_mil_3rd, \n" +
            "            party_close_rate_3rd, \n" +
            "            compliance_total, \n" +
            "            comp_customer, \n" +
            "            comp_internal, \n" +
            "            fox_total, \n" +
            "            fox_ict, \n" +
            "            fox_spi, \n" +
            "            fox_fpy, \n" +
            "            fox_delay, \n" +
            "            spi_input, \n" +
            "            spi_output, \n" +
            "            spi_fpy, \n" +
            "            aoi_input, \n" +
            "            aoi_fp_qty, \n" +
            "            aoi_output, \n" +
            "            aoi_fpy, \n" +
            "            aoi_fy, \n" +
            "            ict_input, \n" +
            "            ict_fp_qty, \n" +
            "            ict_output, \n" +
            "            ict_fpy, \n" +
            "            ict_fy, \n" +
            "            ipqc_latest_close_mil, \n" +
            "            party_latest_close_mil" +
            "        ) VALUES\n" +
            "<foreach collection='dataList' item='item' separator=','>" +
            "            (\n" +
            "                #{item.id}, \n" +
            "                #{item.year}, \n" +
            "                #{item.month}, \n" +
            "                #{item.line}, \n" +
            "                #{item.claimTotal}, \n" +
            "                #{item.claimH1}, \n" +
            "                #{item.claimC}, \n" +
            "                #{item.sortingFeeTotal}, \n" +
            "                #{item.sortingFeeIqc}, \n" +
            "                #{item.sortingFeeClaim}, \n" +
            "                #{item.inputAmount}, \n" +
            "                #{item.scarpAmount}, \n" +
            "                #{item.scarpRate}, \n" +
            "                #{item.nonConformity}, \n" +
            "                #{item.capa}, \n" +
            "                #{item.oqcScanQty}, \n" +
            "                #{item.oqcScanNgQty}, \n" +
            "                #{item.oqcScanNg}, \n" +
            "                #{item.oqcInspLot}, \n" +
            "                #{item.oqcRejectLot}, \n" +
            "                #{item.oqcLrr}, \n" +
            "                #{item.oqcInspQty}, \n" +
            "                #{item.oqcNgQty}, \n" +
            "                #{item.oqcDppm}, \n" +
            "                #{item.obaTimes}, \n" +
            "                #{item.obaRejectTime}, \n" +
            "                #{item.obaNg}, \n" +
            "                #{item.ipqcFindings}, \n" +
            "                #{item.ipqcMajor}, \n" +
            "                #{item.ipqcMinor}, \n" +
            "                #{item.ipqcCloseMil}, \n" +
            "                #{item.ipqcCloseRate}, \n" +
            "                #{item.partyFindings3Rd}, \n" +
            "                #{item.partyMajor3Rd}, \n" +
            "                #{item.partyMinor3Rd}, \n" +
            "                #{item.partyCloseMil3Rd}, \n" +
            "                #{item.partyCloseRate3Rd}, \n" +
            "                #{item.complianceTotal}, \n" +
            "                #{item.compCustomer}, \n" +
            "                #{item.compInternal}, \n" +
            "                #{item.foxTotal}, \n" +
            "                #{item.foxIct}, \n" +
            "                #{item.foxSpi}, \n" +
            "                #{item.foxFpy}, \n" +
            "                #{item.foxDelay}, \n" +
            "                #{item.spiInput}, \n" +
            "                #{item.spiOutput}, \n" +
            "                #{item.spiFpy}, \n" +
            "                #{item.aoiInput}, \n" +
            "                #{item.aoiFpQty}, \n" +
            "                #{item.aoiOutput}, \n" +
            "                #{item.aoiFpy}, \n" +
            "                #{item.aoiFy}, \n" +
            "                #{item.ictInput}, \n" +
            "                #{item.ictFpQty}, \n" +
            "                #{item.ictOutput}, \n" +
            "                #{item.ictFpy}, \n" +
            "                #{item.ictFy},\n" +
            "                #{item.ipqcLatestCloseMil},\n" +
            "                #{item.partyLatestCloseMil}\n" +
            "            )\n" +
            "        </foreach>" +
            " ON DUPLICATE KEY UPDATE " +
            "year = VALUES(year), " +
            "month = VALUES(month), " +
            "line = VALUES(line), " +
            "claim_total = VALUES(claim_total), " +
            "claim_h1 = VALUES(claim_h1), " +
            "claim_c = VALUES(claim_c), " +
            "sorting_fee_total = VALUES(sorting_fee_total), " +
            "sorting_fee_iqc = VALUES(sorting_fee_iqc), " +
            "sorting_fee_claim = VALUES(sorting_fee_claim), " +
            "input_amount = VALUES(input_amount), " +
            "scarp_amount = VALUES(scarp_amount), " +
            "scarp_rate = VALUES(scarp_rate), " +
            "non_conformity = VALUES(non_conformity), " +
            "capa = VALUES(capa), " +
            "oqc_scan_qty = VALUES(oqc_scan_qty), " +
            "oqc_scan_ng_qty = VALUES(oqc_scan_ng_qty), " +
            "oqc_scan_ng = VALUES(oqc_scan_ng), " +
            "oqc_insp_lot = VALUES(oqc_insp_lot), " +
            "oqc_reject_lot = VALUES(oqc_reject_lot), " +
            "oqc_lrr = VALUES(oqc_lrr), " +
            "oqc_insp_qty = VALUES(oqc_insp_qty), " +
            "oqc_ng_qty = VALUES(oqc_ng_qty), " +
            "oqc_dppm = VALUES(oqc_dppm), " +
            "oba_times = VALUES(oba_times), " +
            "oba_reject_time = VALUES(oba_reject_time), " +
            "oba_ng = VALUES(oba_ng), " +
            "ipqc_findings = VALUES(ipqc_findings), " +
            "ipqc_major = VALUES(ipqc_major), " +
            "ipqc_minor = VALUES(ipqc_minor), " +
            "ipqc_close_mil = VALUES(ipqc_close_mil), " +
            "ipqc_close_rate = VALUES(ipqc_close_rate), " +
            "party_findings_3rd = VALUES(party_findings_3rd), " +
            "party_major_3rd = VALUES(party_major_3rd), " +
            "party_minor_3rd = VALUES(party_minor_3rd), " +
            "party_close_mil_3rd = VALUES(party_close_mil_3rd), " +
            "party_close_rate_3rd = VALUES(party_close_rate_3rd), " +
            "compliance_total = VALUES(compliance_total), " +
            "comp_customer = VALUES(comp_customer), " +
            "comp_internal = VALUES(comp_internal), " +
            "fox_total = VALUES(fox_total), " +
            "fox_ict = VALUES(fox_ict), " +
            "fox_spi = VALUES(fox_spi), " +
            "fox_fpy = VALUES(fox_fpy), " +
            "fox_delay = VALUES(fox_delay), " +
            "spi_input = VALUES(spi_input), " +
            "spi_output = VALUES(spi_output), " +
            "spi_fpy = VALUES(spi_fpy), " +
            "aoi_input = VALUES(aoi_input), " +
            "aoi_fp_qty = VALUES(aoi_fp_qty), " +
            "aoi_output = VALUES(aoi_output), " +
            "aoi_fpy = VALUES(aoi_fpy), " +
            "aoi_fy = VALUES(aoi_fy), " +
            "ict_input = VALUES(ict_input), " +
            "ict_fp_qty = VALUES(ict_fp_qty), " +
            "ict_output = VALUES(ict_output), " +
            "ict_fpy = VALUES(ict_fpy), " +
            "ict_fy = VALUES(ict_fy)," +
            "ipqc_latest_close_mil = VALUES(ipqc_latest_close_mil), " +
            "party_latest_close_mil = VALUES(party_latest_close_mil)" +
            "</script>")
    int batchSave(@Param("dataList") List<Smtdashboard> dataList);
}
